﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

    class Program
    {
        static void permutation(int[] m, int l, int n)
        {
            string s = "";
            if (l == n - 1)
            {
                for (int i = 0; i < n; i++)
                {
                    s += m[i];
                }
                Console.WriteLine(s);
            }
            else
            {
                for (int i = l; i < n; i++)
                {
                    int tmp = m[l];
                    m[l] = m[i];
                    m[i] = tmp;
                    permutation(m, l + 1, n);
                    tmp = m[l];
                    m[l] = m[i];
                    m[i] = tmp;
                }
            }
        }
        static void Main(string[] args)
        {
            int n ;
            Console.WriteLine("Введите число");
            n = Convert.ToInt32(Console.ReadLine());

            int[] m = new int[n];

            for (int i = 0; i < n; i++)
            {
                m[i] = i + 1;
            }
            permutation(m, 0, n);

            Console.ReadLine();
        }
    }
}
